package src.view;

import src.event.*;
import src.event.events.ConsoleUpdateEvent;
import src.event.events.MapUpdateEvent;
import src.event.events.SelectionUpdateEvent;
import src.event.events.TechUpdateEvent;
import src.event.events.CursorChangeEvent;

/**
 * <b>Overview</b>
 * The ViewEventHandler is responsible for notifying the appropriate aspects of the View when an event that requires an update to the View occurs.
 *
 * <b>Responsibilities</b>
 * Receive all incoming events from the Model and Controller that affect the View and notify the appropriate parts of the View.
 *
 * <b>Collaborators</b>
 *
 * <b>Implementor</b> - Bruce
 * <b>Tester</b> - Tim
 *
 * @author Bruce
 */
public abstract class ViewEventHandler
{
	/**
	 * The handler for map events.
	 */
	private static EventListener<MapUpdateEvent> mapHandler;

	/**
	 * The handler for selection events.
	 */
	private static EventListener<SelectionUpdateEvent> selectionHandler;

	/**
	 * The handler for tech events.
	 */
	private static EventHandler<TechUpdateEvent> techHandler;

	/**
	 * The handler for console events.
	 */
	private static EventHandler<ConsoleUpdateEvent> consoleHandler;

	private static EventListener<CursorChangeEvent> cursorHandler;

	public static void setMapListener(EventListener<MapUpdateEvent> handler)
	{
		mapHandler = handler;
	}

	public static void setSelectionListener(EventListener<SelectionUpdateEvent> handler)
	{
		selectionHandler = handler;
	}

	public static void setTechListener(EventHandler<TechUpdateEvent> handler)
	{
		techHandler = handler;
	}

	public static void setConsoleListener(EventHandler<ConsoleUpdateEvent> handler)
	{
		consoleHandler = handler;
	}

	public static void setCursorListener(EventListener<CursorChangeEvent> handler){
		cursorHandler = handler;
	}

	/**
	 * Asynchronously fires the specified MapUpdateEvent.
	 *
	 * @param e the MapUpdateEvent to fire.
	 */
	public static void fireEvent(MapUpdateEvent e)
	{
		mapHandler.eventCallback(e);
	}

	/**
	 * Asynchronously fires the specified SelectionUpdateEvent.
	 *
	 * @param e the SelectionUpdateEvent to fire.
	 */
	public static void fireEvent(SelectionUpdateEvent e)
	{
		selectionHandler.eventCallback(e);
	}

	/**
	 * Asynchronously fires the specified TechUpdateEvent.
	 *
	 * @param e the TechUpdateEvent to fire.
	 */
	public static void fireEvent(TechUpdateEvent e)
	{
		techHandler.fireEvent(e);
	}

	/**
	 * Asynchronously fires the specified ConsoleUpdateEvent.
	 *
	 * @param e the ConsoleUpdateEvent to fire.
	 */
	public static void fireEvent(ConsoleUpdateEvent e)
	{
		consoleHandler.fireEvent(e);
	}

	public static void fireEvent(CursorChangeEvent e){
		cursorHandler.eventCallback(e);
	}
}
